/*
 * @Author: your name
 * @Date: 2024-03-21 21:35:43
 * @LastEditTime: 2024-03-21 21:43:51
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\367.有效的完全平方数.cpp
 */
/*
 * @lc app=leetcode.cn id=367 lang=cpp
 *
 * [367] 有效的完全平方数
 */

// @lc code=start
class Solution {
public:
    bool isPerfectSquare(int num) {
        int left = 0, right = num;
        while(left <= right){
            long long  mid = left + (right-left)/2;
            if(mid*mid > num){
                right = mid -1;
            }
            else if(mid * mid < num){
                left = left + 1;
            }
            else{
                return true;
            }
        }
        return false;
    }
};
// @lc code=end

